/*
 * spi.c
 *
 *  Created on: 2023年2月24日
 *      Author: 15516
 */
#include "spi.h"
#include "hbird_sdk_soc.h"
void SPI_init()
{
	gpio_enable_output(GPIOA, SPI_SCK);
	gpio_enable_output(GPIOA, SPI_MOSI);
	gpio_enable_output(GPIOA, SPI_CS);
	//gpio_enable_input(GPIOA, SPI_MISO);
}

uint8_t SOFT_SPI_RW_MODE0( uint8_t write_dat )
{
	uint8_t i, read_dat;
	    for( i = 0; i < 8; i++ )
	    {
	        if( write_dat & 0x80 )
	            MOSI_H;
	        else
	            MOSI_L;
	        write_dat <<= 1;
	        delay_1ms(1);
	        SCK_H;
	        read_dat <<= 1;
	        if( MISO )
	            read_dat++;
			delay_1ms(1);
	        SCK_L;
	    }

	    return read_dat;
}

